<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app1" style="border: 1px solid black;">
    <h3>这是app1的作用域</h3>
    <my-component></my-component>
  </div>
  <div id="app2" style="border: 1px solid black;">
    <h3>这是app2的作用域</h3>
    <my-component></my-component>
  </div>
  
  <template id="template1">
    <button @click='addCount'>全局组件，被点击次数是{{count}}</button>
  </template>
  
  <script src="js/vue.js"></script>
  <script>
    // 创建Vue实例app1
    const app1 = new Vue({
      el: '#app1',
      components: {
        // 局部组件，组件名为my-component
        "my-component": {
          // 通过选择器指向组件的模板
          template: `#template1`,
          data() {
            return {
              count: 0
            };
          },
          methods: {
            addCount() {
              this.count++;
            }
          }
        }
      }
    });
  
    // 创建Vue实例app2，未定义局部组件
    const app2 = new Vue({
      el: '#app2'
    });
  </script>
</body>
</html>